//
//  BallSprite.m
//  618
//
//  Created by Ling on 13-6-24.
//  Copyright 2013年 __MyCompanyName__. All rights reserved.
//

#import "BallSprite.h"
#import "GameLayer.h"


@implementation BallSprite
@synthesize x,y,type,del,score;

- (void) dealloc
{
    [normalAnimation release];
    [activeAnimation release];
    [super dealloc];
}

- (void)load {
    selected = NO;
    [self setScale:0.1];
    //let the sprite scale up
    id minScale = [CCScaleBy actionWithDuration:0.05 scale:5];
    id normal = [CCScaleBy actionWithDuration:0.05 scale:2];
    id seq = [CCSequence actions:minScale,normal, nil];
    [self runAction:seq];

}
- (void)remove {
    
    id minScale = [CCScaleBy actionWithDuration:0.1 scale:0.01];
    [self runAction:minScale];
    
}
- (void)jump {
    
    id moveup = [CCMoveTo actionWithDuration:0.1 position:ccp(self.position.x,self.position.y+ROWS_WIDTH/3)];
    id movedown = [CCMoveTo actionWithDuration:0.1 position:self.position];
    id seq = [CCSequence actions:moveup,movedown, nil];
    [self runAction:seq];
    
}


//点击事件
- (void)touchUnSelect {
    
    selected = NO;
    CCSpriteFrame* frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%d_up.png",self.type]];
    [self setDisplayFrame:frame];

    
}

- (void)touchSelect {
    
    selected = YES;
    CCSpriteFrame* frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%d_down.png",self.type]];
    [self setDisplayFrame:frame];
    [self jump];

}


// /////////////////////
// start 存储收藏data数据
// /////////////////////
- (id) initWithCoder: (NSCoder *)coder {
    self = [self init];
    if (self != nil)
    {
        self.x = [coder decodeIntForKey: @"x"];
        self.y = [coder decodeIntForKey: @"y"];
        self.type = [coder decodeIntForKey:@"type"];
        self.del = [coder decodeBoolForKey: @"del"];
        self.score = [coder decodeIntForKey: @"score"];
    }
    return self;
}

- (void) encodeWithCoder: (NSCoder *)coder {
    [coder encodeInt:self.x forKey:@"x"];
    [coder encodeInt:self.y forKey:@"y"];
    [coder encodeInt:self.type forKey:@"type"];
    [coder encodeBool:self.del forKey:@"del"];
    [coder encodeInt:self.score forKey:@"score"];
    
    
}
//end  存储收藏data数据




@end
